//
//  FKModifyPayPwdVC.m
//  inspectVehicle
//
//  Created by Macbook Pro on 2018/12/12.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKModifyPayPwdVC.h"

@interface FKModifyPayPwdVC ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *oldPwdField;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UITextField *confirmPwdField;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;

@end

@implementation FKModifyPayPwdVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (![string isEqualToString:@""]) {
        if (![string fk_isPureInt]) {
            return false;
        }
        if (textField.text.length >= 6 ) {
            return false;
        }
    }
    return true;
}

- (IBAction)confirmBtnClicked:(UIButton *)sender {
    [self.view endEditing:true];
    
    if (self.oldPwdField.text.length != 6) {
        [SVProgressHUD showInfoWithStatus:@"请输入6位数的旧密码"];
        return;
    }
    if (self.pwdField.text.length != 6) {
        [SVProgressHUD showInfoWithStatus:@"请输入6位数的新密码"];
        return;
    }
    if (self.confirmPwdField.text.length != 6) {
        [SVProgressHUD showInfoWithStatus:@"请输入6位数的确认密码"];
        return;
    }
    if ([self.oldPwdField.text isEqualToString:self.pwdField.text]) {
        [SVProgressHUD showInfoWithStatus:@"原密码与新密码不能一致"];
        return;
    }
    if (![self.pwdField.text isEqualToString:self.confirmPwdField.text]) {
        [SVProgressHUD showInfoWithStatus:@"新密码与确认密码不一致!"];
        return;
    }
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"oldpwd"] = self.oldPwdField.text;
    param[@"newpwd"] = self.pwdField.text;
    param[@"confirm_password"] = self.confirmPwdField.text;
    [SVProgressHUD show];
    [FKHttpTool postWithSuffix:@"m=Home&c=Mine&a=update_pay" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            [SVProgressHUD showSuccessWithStatus:@"支付密码修改成功!"];
            fkPopVC;
        }
    } failure:nil];
}

@end
